#ifndef CONTENTMANAGER_H_
#define CONTENTMANAGER_H_

#include <iostream>
#include <pthread.h>
#include "HTTPConnection.h"
#include "ModuleManager.h"
#include "WebSocketConnection.h"
using namespace std;

class URLManager {
public:
	URLManager(ModuleManager* modMan);
	URLManager();
	virtual ~URLManager();
	virtual void processGET(HTTPConnection* conn);
	virtual void processPOST(HTTPConnection* conn);
	virtual void handleWebSocket(WebSocketConnection* conn);
	virtual string getName();
	virtual void initialize();
	static bool serveFile(HTTPConnection* conn, string path);

protected:
	void addSubManager(URLManager* man);
	void removeSubManager(URLManager* man);
	bool callSubGET(HTTPConnection* conn);
	bool callSubPOST(HTTPConnection* conn);
	bool callSubWebSocket(WebSocketConnection* conn);
	static bool checkSuffix(string name, string suffix);
	static string handleSSI(string SSI, HTTPConnection* conn);

private:
	URLManager* callSub(HighLevelConnection* conn);
	ModuleManager* modMan;
	URLManager** subList;
	int subListCount;
	pthread_rwlock_t subListLock;
};

#endif /* CONTENTMANAGER_H_ */
